//
//  WordChipCell.swift
//  Game
//
//  Created by woniu on 2025/9/2.
//

import UIKit

final class WordChipCell: UICollectionViewCell {
    static let reuseId = "WordChipCell"

    private let titleLabel = UILabel()
    private let bgView = UIView()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setup()
    }

    private func setup() {
        contentView.addSubview(bgView)
        bgView.layer.cornerRadius = 24
        bgView.layer.masksToBounds = false
        bgView.layer.shadowColor = UIColor.black.cgColor
        bgView.layer.shadowOpacity = 0.08
        bgView.layer.shadowRadius = 6
        bgView.layer.shadowOffset = CGSize(width: 0, height: 3)
        bgView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }

        bgView.addSubview(titleLabel)
        titleLabel.font = UIFont.systemFont(ofSize: 20, weight: .bold)
        titleLabel.snp.makeConstraints { make in
            make.center.equalToSuperview()
        }
    }

    func configure(text: String, color: UIColor, selected: Bool) {
        titleLabel.text = text
        // 使用柔和的背景色，降低饱和度/亮度感知
        bgView.backgroundColor = color.withAlphaComponent(0.22)
        if selected {
            bgView.layer.borderWidth = 3
            bgView.layer.borderColor = color.cgColor
        } else {
            bgView.layer.borderWidth = 0
            bgView.layer.borderColor = UIColor.clear.cgColor
        }
    }
}


